import request from '@/utils/request'

// 查询商品表列表
export function listArtGood(query) {
  return request({
    url: '/artGood/artGood/list',
    method: 'get',
    params: query
  })
}

// 查询商品表详细
export function getArtGood(goodId) {
  return request({
    url: '/artGood/artGood/' + goodId,
    method: 'get'
  })
}

// 新增商品表
export function addArtGood(data) {
  return request({
    url: '/artGood/artGood',
    method: 'post',
    data: data
  })
}

// 修改商品表
export function updateArtGood(data) {
  return request({
    url: '/artGood/artGood',
    method: 'put',
    data: data
  })
}

// 删除商品表
export function delArtGood(goodId) {
  return request({
    url: '/artGood/artGood/' + goodId,
    method: 'delete'
  })
}

// 上移
export function moveUp(goodId) {
  return request({
    url: '/artGood/artGood/moveUp',
    method: 'post',
    data: goodId // 直接传递goodId值
  })
}

// 下移
export function moveDown(goodId) {
  return request({
    url: '/artGood/artGood/moveDown',
    method: 'post',
    data: goodId // 直接传递goodId值
  })
}

// 获取前一条记录
export function selectPrevArtGood(currentSort) {
  return request({
    url: '/artGood/artGood/selectPrevArtGood', // 修正路径
    method: 'get',
    params: { currentSort }
  })
}

// 获取后一条记录
export function selectNextArtGood(currentSort) {
  return request({
    url: '/artGood/artGood/selectNextArtGood', // 修正路径
    method: 'get',
    params: { currentSort }
  })
}

// 批量更新排序值
export function batchUpdateSort(list) {
  return request({
    url: '/artGood/artGood/batchUpdateSort', // 修正路径
    method: 'post',
    data: list
  })
}


// 图片上传
export function uploadIdCard(data) {
  return request({
    url: '/files/upload',
    method: 'post',
    headers: {'Content-Type':'multipart/form-data'},
    data: data
  })
}

// ================= 分销商品相关接口 =================

// 查询本校区的所有商品（用于分销商品组件）
export function getOwnCampusGoods(campusId) {
  return request({
    url: '/artGood/artGood/ownCampusGoods',
    method: 'get',
    params: { campusId: Number(campusId) }
  })
}

// 查询可分销的校区列表
export function getDistributionCampusList() {
  return request({
    url: '/campus/campusInfo/distributionList',
    method: 'get'
  })
}

// 查询指定校区的分销商品列表
export function getDistributionGoods(campusId) {
  return request({
    url: '/artGood/artGood/distributionGoods',
    method: 'get',
    params: { campusId: Number(campusId) }
  })
}

// 查询所有分销商品（跨校区）
export function getAllDistributionGoods(query) {
  return request({
    url: '/artGood/artGood/allDistributionGoods',
    method: 'get',
    params: query
  })
}

// 分销商品搜索
export function searchDistributionGoods(query) {
  return request({
    url: '/artGood/artGood/searchDistribution',
    method: 'get',
    params: query
  })
}
